package com.example.comiccenter.controller;


import com.example.comiccenter.domain.Comment;
import com.example.comiccenter.service.CommentService;
import com.example.comiccenter.utils.ResultData;
import com.example.comiccenter.utils.SearchBean;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private CommentService commentService;



    //查看某comic下的所有评论以及其子评论
    @PostMapping("/getComicComment")
    public ResultData getComicComment(@RequestParam int id,@RequestParam String column){
        return commentService.getComicComment(id,column);
    }


    //分页查询
    @PostMapping("/getAllComment")
    public ResultData selectPage(@RequestBody SearchBean<Comment> searchBean){
        System.out.println("查询comment");
        return commentService.getAllComment(searchBean);
    }

    //添加收藏
    @PostMapping("/addComment")
    public ResultData addcomment(@RequestBody Comment comment){
        comment.setDislikes(0);
        comment.setLikes(0);
        comment.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return commentService.addComment(comment);
    }

    //取消收藏
    @PostMapping("/deleteComment")
    public ResultData deletecomment(@RequestBody Comment comment){
        System.out.println("删除comment："+comment);
        return commentService.deleteComment(comment);
    }
}
